package View;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

public class LoginPanel extends JPanel implements ActionListener {

	JLabel jlabel, jlabel1, jlabel2;
	JTextField jTextField;

	JPasswordField jPasswordFieldeld;
	JButton jbutton1, jbutton2;

	public LoginPanel() {
		
		setVisible(true);
		setLocation(200, 200);
		;
		Font font = new Font("微软雅黑", Font.TRUETYPE_FONT, 20);
		setLayout(null);
		
        jlabel=new JLabel("请连接数据库");
        jlabel.setFont(font);
  		jlabel.setBounds(250, 100, 300, 40);
  		add(jlabel);
		jlabel1 = new JLabel("用户名:");
		jlabel1.setFont(font);
		jlabel1.setBounds(150, 170, 100, 40);
		add(jlabel1);
		jTextField = new JTextField();
		jTextField.setFont(font);
		jTextField.setBounds(250, 170, 200, 40);
		
		add(jTextField);
		jTextField.addActionListener(this);
		jlabel2 = new JLabel("密码:");
		jlabel2.setFont(font);
		jlabel2.setBounds(150, 250, 100, 40);
		add(jlabel2);
		jPasswordFieldeld = new JPasswordField();
		jPasswordFieldeld.setFont(font);
		
		jPasswordFieldeld.setBounds(250, 250, 200, 40);
		
				
		add(jPasswordFieldeld);
	
		jbutton1=new JButton("连接");
		jbutton1.setFont(font);
		jbutton1.setBounds(180,330,100,40);
		
		add(jbutton1);
		jbutton1.addActionListener(this);
		jbutton2=new JButton("退出");
		jbutton2.setFont(font);
		jbutton2.setBounds(300,330,100,40);
		add(jbutton2);
		jbutton2.addActionListener(this);
		
		
		
	}

	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {
				new LoginPanel();
			}
		});
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == jTextField) {
			String user = jTextField.getText();
			String password = jTextField.getText();
			//验证 略
			if(user.equals("")||password.equals("")){
				JOptionPane.showMessageDialog(this, "请输入用户名和密码！");
				return;
			}
		
	}
		
			
		}
		protected void paintComponent(Graphics g) {
			// TODO Auto-generated method stub
			super.paintComponent(g);
			Image img =new ImageIcon(getClass().getResource("../image/3.jpg")).getImage();
			g.drawImage(img, 0, 0, this);
	}

		

}
